﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PaceR.Examples.MVC.Models;
using PaceR.Examples.MVC.Library;

namespace PaceR.Examples.MVC.Controllers.Examples
{
    public class UserManagerController : BaseController
    {
        //
        // GET: /UserManager/

        public ActionResult Index()
        {
            return View(UserProfileAgent.GetAllUsers());
        }

        //
        // GET: /UserManager/Details/5

        public ActionResult Details(string id)
        {
            return View(UserProfileAgent.GetUser(id));
        }

        //
        // GET: /UserManager/Create

        public ActionResult Create()
        {
            return View("Create");
        }

        //
        // POST: /UserManager/Create

        [HttpPost]
        public ActionResult Create(UserProfile profile)
        {
            try
            {
                // TODO: Add insert logic here
                UserProfileAgent.Save(profile);

                return RedirectToAction("Details", new { id = profile.Username });
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /UserManager/Edit/5

        public ActionResult Edit(string id)
        {
            return View(UserProfileAgent.GetUser(id));
        }

        //
        // POST: /UserManager/Edit/5

        [HttpPost]
        public ActionResult Edit(string id, UserProfile profile)
        {
            try
            {
                // TODO: Add update logic here
                UserProfileAgent.Save(profile);

                return RedirectToAction("Details", new { id = profile.Username });
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /UserManager/Delete/5

        public ActionResult Delete(string id)
        {
            return View(UserProfileAgent.GetUser(id));
        }

        //
        // POST: /UserManager/Delete/5

        [HttpPost]
        public ActionResult Delete(string id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                UserProfileAgent.DeleteUser(id);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
